package com.userInfoService.actuator;

import org.springframework.beans.BeansException;
import org.springframework.boot.actuate.endpoint.AbstractEndpoint;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.userInfoService.service.StatusService;
/*
 * 通过@ConfigurationProperties，我们可以在application.properties中通过endpoints.myStatus配置我们的端点，
 * 如：endpoints.myStatus.enabled=false可以关闭该端点
 * 当然也可以不要该注解
 */
@ConfigurationProperties(prefix = "endpoints.myStatus",ignoreUnknownFields = false)
public class StatusEndPoint extends AbstractEndpoint<String> implements ApplicationContextAware{
	private ApplicationContext context;
	public StatusEndPoint() {
		super("myStatus");
	}

	@Override
	public String invoke() {
		//直接通过@Autowired注入也可以
		StatusService statusService = context.getBean(StatusService.class);
		return "The Current Status is :" + statusService.getMyStatus();
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		this.context = applicationContext;
		
	}
}
